package o;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.net.Uri;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;
import o.exp.d;
import o.exp.j;

public class far extends BaseAlertDialog {
    private int ʻ = 80;
    private ScrollView ʼ;
    private AlertDialog ʽ;
    private WebView ˋ;
    private OnDismissListener ˋॱ;
    private String ˎ;
    protected Activity ॱ;
    private String ॱॱ;
    private Intent ᐝ;

    far(Activity activity, Intent intent) {
        super(activity, "", null);
        this.ॱ = activity;
        this.ᐝ = intent;
    }

    public void ˎ(OnDismissListener onDismissListener) {
        this.ˋॱ = onDismissListener;
        if (this.ʽ != null) {
            this.ʽ.setOnDismissListener(this.ˋॱ);
        }
    }

    public void ॱ() {
        ᐝ();
        try {
            this.ʽ.show();
            ayw.ˊ(this.ʽ.getWindow());
            ˊ();
        } catch (Throwable e) {
            Logger.ˋ("GameServiceNoticeDialog", "setContent", e);
        }
        this.ʽ.setOnDismissListener(this.ˋॱ);
        ezr.ˎ().ॱ(this.ॱॱ);
        this.ʽ.setCancelable(false);
    }

    public void ˏ() {
        if (this.ʽ != null) {
            this.ʽ.dismiss();
        }
    }

    private void ˊ() {
        Window window = this.ʽ.getWindow();
        window.setContentView(j.ˈ);
        ˊ(window, this.ॱ);
        String stringExtra = this.ᐝ.getStringExtra("filePath");
        this.ॱॱ = this.ᐝ.getStringExtra("appId");
        this.ʻ = this.ᐝ.getIntExtra("heightPercent", 80);
        if (Logger.ˎ()) {
            Logger.ˏ("GameServiceNoticeDialog", "heightPercent:" + this.ʻ);
        }
        if (dof.ˋ(stringExtra)) {
            if (Logger.ˎ()) {
                Logger.ˏ("GameServiceNoticeDialog", "filePath is invalid ");
            }
            this.ʽ.dismiss();
        } else if (dof.ˋ(this.ॱॱ)) {
            if (Logger.ˎ()) {
                Logger.ˏ("GameServiceNoticeDialog", "appId is invalid ");
            }
            this.ʽ.dismiss();
        } else {
            ((TextView) window.findViewById(d.ˎˏ)).setText(this.ᐝ.getStringExtra("noticeTitle"));
            this.ˎ = this.ᐝ.getStringExtra("detailUrl");
            String str = (dof.ˋ(this.ˎ) || !this.ˎ.startsWith("higame://openapp?")) ? "" : this.ˎ;
            this.ˎ = str;
            ˊ(window, this.ˎ);
            this.ʼ = (ScrollView) window.findViewById(d.ॱˍ);
            ʻ();
            this.ˋ = (WebView) window.findViewById(d.ॱˉ);
            ʼ();
            this.ˋ.loadUrl("file://" + stringExtra);
        }
    }

    private void ˊ(Window window, final String str) {
        Button button = (Button) window.findViewById(d.ʽˊ);
        Button button2 = (Button) window.findViewById(d.ʽᐝ);
        button.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ far ˏ;

            public void onClick(View view) {
                try {
                    Intent intent = new Intent(ACTION.HWID_SCHEME_URL, Uri.parse(str));
                    ezr.ˎ().ˏ(this.ˏ.ॱॱ);
                    this.ˏ.ॱ.startActivity(intent);
                } catch (Exception e) {
                    Logger.ˋ("GameServiceNoticeDialog", "onClick error");
                }
                ezr.ˎ().ˊ(this.ˏ.ॱॱ);
                this.ˏ.ʽ.dismiss();
            }
        });
        button2.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ far ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                ezr.ˎ().ˊ(this.ˎ.ॱॱ);
                this.ˎ.ʽ.dismiss();
            }
        });
        if (str.equals("")) {
            button.setVisibility(8);
            button2.setText(exp$f.ˋʽ);
            button2.setAllCaps(true);
            return;
        }
        button.setVisibility(0);
        button.setText(exp$f.ˌॱ);
        button.setAllCaps(true);
        button2.setText(exp$f.ˊʽ);
        button2.setAllCaps(true);
    }

    private void ᐝ() {
        this.ʽ = new Builder(new ContextThemeWrapper(this.ॱ, exp$i.ˋ)).create();
    }

    private void ʼ() {
        if (this.ˋ != null) {
            this.ˋ.setBackgroundColor(0);
            this.ˋ.getSettings().setJavaScriptEnabled(false);
            this.ˋ.getSettings().setDefaultTextEncodingName("UTF-8");
            this.ˋ.getSettings().setUseWideViewPort(true);
            this.ˋ.getSettings().setLoadWithOverviewMode(true);
            this.ˋ.getSettings().setBuiltInZoomControls(false);
            this.ˋ.getSettings().setSupportZoom(false);
            this.ˋ.getSettings().setDisplayZoomControls(false);
            this.ˋ.getSettings().setBlockNetworkImage(true);
            this.ˋ.getSettings().setAllowContentAccess(false);
            this.ˋ.getSettings().setSavePassword(false);
            this.ˋ.getSettings().setAllowFileAccessFromFileURLs(false);
            this.ˋ.getSettings().setAllowUniversalAccessFromFileURLs(false);
            this.ˋ.getSettings().setMixedContentMode(1);
            this.ˋ.setVerticalScrollBarEnabled(false);
            this.ˋ.setHorizontalScrollBarEnabled(false);
            this.ˋ.requestFocus();
            this.ˋ.removeJavascriptInterface("accessibility");
            this.ˋ.removeJavascriptInterface("accessibilityTraversal");
            this.ˋ.removeJavascriptInterface("searchBoxJavaBridge_");
        }
    }

    private int ˊ(Context context) {
        if (context.getResources().getConfiguration().orientation == 2) {
            return (int) (0.888d * ((double) epv.ˎ(context)));
        }
        int ॱ = (this.ʻ * epv.ॱ(context)) / 100;
        if (!Logger.ˎ()) {
            return ॱ;
        }
        Logger.ˏ("GameServiceNoticeDialog", "height: " + epv.ॱ(context));
        Logger.ˏ("GameServiceNoticeDialog", "maxHeight: " + ॱ);
        return ॱ;
    }

    private void ˊ(Window window, Context context) {
        LayoutParams attributes = window.getAttributes();
        if (context.getResources().getConfiguration().orientation == 2) {
            attributes.width = (int) (1.085d * ((double) epv.ˎ(context)));
        } else {
            attributes.width = epv.ˎ(context);
        }
        window.setAttributes(attributes);
    }

    private void ʻ() {
        if (Logger.ˎ()) {
            Logger.ˏ("GameServiceNoticeDialog", "start to check height");
        }
        if (this.ʼ != null) {
            int ˊ = ˊ(this.ॱ) - epv.ˋ(this.ॱ, 135);
            if (ˊ < 0) {
                ˊ = 0;
            }
            ViewGroup.LayoutParams layoutParams = this.ʼ.getLayoutParams();
            layoutParams.height = ˊ;
            this.ʼ.setLayoutParams(layoutParams);
        }
    }
}
